<template>
  <a-spin :spinning='spinning'>
    <a-card :bordered='false'>
      <!-- 查询区域 -->
      <div class='table-page-search-wrapper'>
        <a-form layout='inline' @keyup.enter.native='searchQuery'>
          <div v-show='toggleSearchStatus'>
            <a-row :gutter='24'>
              <a-col>
                <a-form-model-item label='年级' prop='queryParam.gradeId'>
                  <s-dict-select-tag v-model='queryParam.gradeId' @change='changeGradeId' placeholder='请选择年级'
                                     dictCode='cou_grade,grade_name,id,tenant_id  is not null order by  grade_order' />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter='24' style='height: 85px'>
              <a-col>
                <a-form-model-item label='班级' prop='queryParam.classId'>
                  <s-dict-select-tag placeholder='请选择班级' style='overflow-y: scroll;height: 80px'
                                     @change='getCourseArrangeId' v-model='queryParam.classId'
                                     :dictCode='queryParamSelect.classIdSelect' />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter='24'>
              <a-col>
                <a-form-model-item label='课表模板' prop='queryParam.courseArrangeId'>
                  <s-dict-select-tag v-model='queryParam.courseArrangeId' @change='getTargetByClassId'
                                     :options='courseArrange' placeholder='课表模板' />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter='24'>
              <a-col style='height: 75px'>
                <a-form-model-item label='科目' prop='queryParam.subjectId'>
                  <s-dict-select-tag style='overflow-y: scroll;height: 70px' placeholder='请选择科目'
                                     v-model='queryParam.subjectId'
                                     @change='handleSubjectChange'
                                     dictCode='cou_subject,subject_name,id,subject_iz_open =1 and del_flag =0  order by subject_order'></s-dict-select-tag>

                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter='24' style='height: 85px'>
              <a-col>
                <a-form-model-item label='教师' prop='queryParam.teacherId'>
                  <s-multi-select-tag :options='teacherList' v-model='queryParam.teacherId' placeholder='请选择教师'>
                  </s-multi-select-tag>
                </a-form-model-item>
              </a-col>
            </a-row>

            <a-row :gutter='24' style='margin-top: 40px'>
              <a-col>
                <label>教学周次：</label>
                <a-button style='margin-left: 5px' :type='item.types' @click='onSetDate(item)' v-for='item in whereData'
                          :size='sizeButton'
                          shape='circle'>
                  {{ item.weekSetIndex }}
                </a-button>
              </a-col>
            </a-row>
            <a-row :gutter='24' style='margin-top: 30px'>
              <a-col>
                <label>周次日期：</label>
                <a-space direction='vertical' :size='12'>
                  <a-range-picker @change='onChangeDate' disabled v-model:value='weekSetIndexDate'
                                  :format='dateFormat' />
                </a-space>
              </a-col>
            </a-row>
          </div>
          <a-row :gutter='24'>
            <a-col :offset='8'>
            <span style='overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='getTargetByClassId' icon='search'>查询</a-button>
              <a-button type='primary' @click='handleCleanSearch' icon='reload' style='margin-left: 8px'>重置</a-button>
               <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->


      <div style='margin-left: 200px'>
        <a-row justify='center'>
          <a-col span='6'>
            <a-card class='week-c' hoverable v-if='this.oneData != null'>
              <img @click="onSelectBt('one')"
                   style='width: 15%;height: 15%;position: absolute;top: 0;right: 0;cursor: pointer'
                   src='@/assets/cuowu.png'>
              <div style='text-align: center'>
                <!-- 默认有三个参数，text为传给该列每个单元格中的数据，record为每一行的数据，index为改行索引 -->
                <a-row justify='center' style='color: #00DB00'
                       v-if='oneData.subjectName == "休息" && oneData.holiday != "false"'>
                  <a-col span='24'>休息</a-col>
                </a-row>
                <div style='font-size: 3px' v-else>
                  <a-row justify='center'>
                    <a-col span='12' style='text-align: center;color: #7ac23c'>{{ oneData.teacherName }}</a-col>
                    <a-col span='12' style='text-align: left'>{{ oneData.className }}</a-col>
                  </a-row>
                  <a-row justify='center'>
                    <a-col span='12' style='text-align: center;color: #2276d2'>{{ oneData.subjectName }}</a-col>
                    <a-col span='12' style='text-align: left'>{{ oneData.classroomName }}</a-col>
                  </a-row>
                  <a-row justify='center' style='color: #00DB00'>
                    <a-col span='24'>{{ oneData.weekName }}</a-col>
                  </a-row>
                  <a-row justify='center' style='color: #00DB00'>
                    <a-col span='24'>{{ oneData.holiday == 'true' ? '休息' : '' }}</a-col>
                  </a-row>
                </div>
              </div>
            </a-card>
          </a-col>
          <a-col span='3'>
            <div hoverable v-show='this.tooData != null && this.oneData != null'>
              <div style='line-height: 120px;font-size: 5px;'>
                <a-button @click='exchangeCourse' style='size: 5px' type='primary'><-临时换课-></a-button>
              </div>
            </div>
            <div hoverable v-show='this.oneData != null && this.tooData == null'>
              <template>
                <a-row type='flex' justify='center' align='top' style='width: 400px;line-height: 80px'>
                  <a-col :span='18'>
                    <j-select-multi-teacher v-model='teachers'></j-select-multi-teacher>
                  </a-col>
                  <a-col :span='2' style='margin-left: 5px'>
                    <a-button @click='changeCouresTeacher' style='size: 5px;' type='primary'>临时代课</a-button>
                  </a-col>
                </a-row>
              </template>
            </div>
          </a-col>
          <a-col span='6'>
            <a-card class='week-c' hoverable v-if='this.tooData != null'>
              <img @click="onSelectBt('too')"
                   style='width: 15%;height: 15%;position: absolute;top: 0;right: 0;cursor: pointer'
                   src='@/assets/cuowu.png'>
              <div style='text-align: center'>
                <!-- 默认有三个参数，text为传给该列每个单元格中的数据，record为每一行的数据，index为改行索引 -->
                <a-row justify='center' style='color: #00DB00'
                       v-if='tooData.subjectName == "休息" && tooData.holiday != "false"'>
                  <a-col span='24'>休息</a-col>
                </a-row>
                <div style='font-size: 3px' v-else>
                  <a-row justify='center'>
                    <a-col span='12' style='text-align: center;color: #7ac23c'>{{ tooData.teacherName }}</a-col>
                    <a-col span='12' style='text-align: left'>{{ tooData.className }}</a-col>
                  </a-row>
                  <a-row justify='center'>
                    <a-col span='12' style='text-align: center;color: #2276d2'>{{ tooData.subjectName }}</a-col>
                    <a-col span='12' style='text-align: left'>{{ tooData.classroomName }}</a-col>
                  </a-row>
                  <a-row justify='center' style='color: #00DB00'>
                    <a-col span='24'>{{ tooData.weekName }}</a-col>
                  </a-row>
                  <a-row justify='center' style='color: #00DB00'>
                    <a-col span='24'>{{ tooData.holiday == 'true' ? '休息' : '' }}</a-col>
                  </a-row>
                </div>
              </div>
            </a-card>
          </a-col>
        </a-row>

      </div>
      <!-- 操作按钮区域 -->
      <div class='table-operator' style='clear: both;margin-top: 20px;'>
        <a-row justify='center'>
          <a-col span='4'>
            <a-form-model-item prop='jSelectOnlValue'>
              <JSelectOnl v-model='jSelectOnlValue' @closeJselectOnl='handleCloseJselectOnl' code='OnlTitle' :title='selectOnlTitle'>
              </JSelectOnl>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row justify='end'>
          <a-col v-show='Object.keys(this.changeObjs).length != 0' span='24' style='text-align: right;color: red'>
            与{{ this.changeObjs.teachingJobExeDate }}号{{ this.changeObjs.teachingJobExeWeekName
            }}第{{ this.changeObjs.teachingJobExeSection }}节 （{{this.changeObjs.teacherName}}/{{this.changeObjs.subjectName}}）课进行了互换
          </a-col>
        </a-row>
      </div>

      <!-- table区域-begin -->
      <a-table
        id="datatable"
        ref='table'
        size='middle'
        :scroll='{x:true}'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='false'
        :loading='loading'
        class='j-table-force-nowrap'
        :customHeaderRow='customHeaderRow'
      >
        <template slot='colName' slot-scope='text, record, index'>
          <div class='week-b' @dblclick='handleColTableChange(text)' @click='handleColTableQuery(text)'>
            <!-- 默认有三个参数，text为传给该列每个单元格中的数据，record为每一行的数据，index为改行索引 -->
            <a-row justify='center' style='color: #00DB00' v-if='text.subjectName == "休息" && text.holiday != "false"'>
              <a-col>休息</a-col>
            </a-row>
            <div style='font-size: 1px;' v-else>
              <a-row>
                <a-col style='color: #7ac23c'>{{ text.teacherName }}&nbsp;&nbsp;{{ text.className }}</a-col>
              </a-row>
              <a-row>
                <a-col style='color: #2276d2'>{{ text.subjectName }}&nbsp;&nbsp;{{ text.classroomName }}</a-col>
              </a-row>
              <a-row justify='center' style='color: #00DB00'>
                <a-col span='24'>{{ text.weekName }}</a-col>
              </a-row>
              <a-row justify='center' style='color: #00DB00'>
                <a-col span='24'>{{ text.holiday == 'true' ? '休息' : '上课' }}</a-col>
              </a-row>
              <a-row justify='center' v-show='text.quoteTeachingJobId'
                     style='font-size: 10px;color: red;border-radius: 50%;width: 20px;height: 20px;border: 1px solid red;'>
                <a-col span='24'>换</a-col>
              </a-row>
            </div>
          </div>
        </template>
        <template slot='handTitle'>
          <span style='cursor: pointer' @click='handTitleClick'>Name</span>

        </template>
      </a-table>


      <cou-teaching-job-execute-modal ref='modalForm' @ok='modalFormOk'></cou-teaching-job-execute-modal>
    </a-card>
  </a-spin>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import CouTeachingJobExecuteModal from './modules/CouTeachingJobExecuteModal'
import { SearchOutlined } from '@ant-design/icons-vue'
import { getAction, postAction } from '@/api/manage'
import ImgDragSort from '../../jeecg/ImgDragSort'
import ImagPreview from '../../jeecg/ImagPreview'
import JSelectMultiTeacher from '../components/public/JSelectMultiTeacher'
import { getSubjectList, queryTeacherListBySubject } from '@api/commonAPI'
import { SettingOutlined, EditOutlined, EllipsisOutlined } from '@ant-design/icons-vue'
import JSelectOnl from '../components/modal/JSelectOnl'

/**
 * mixins（混入），官方的描述是一种分发 Vue 组件中可复用功能的非常灵活的方式，mixins是一个js对象，
 * 它可以包含我们组件中script项中的任意功能选项，如data、components、methods 、created、computed等等。
 * 我们只要将共用的功能以对象的方式传入 mixins选项中，当组件使用 mixins对象时所有mixins对象的选项都将被混入该组件本身的选项中来，
 * 这样就可以提高代码的重用性，使你的代码保持干净和易于维护。 JeecgListMixin框架自定义的公共模板
 */
export default {
  name: 'CouTeachingJobExecuteList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ImagPreview,
    ImgDragSort,
    CouTeachingJobExecuteModal,
    SearchOutlined,
    JSelectMultiTeacher,
    SettingOutlined,
    EditOutlined,
    EllipsisOutlined,
    JSelectOnl
    // JSelectMultiTeacher:()=>import('../components/public/JSelectMultiTeacher') //组件异步加载，需要显示时才从服务器加载
  },
  props: {
    queryConfig: {}
  },
  data() {
    return {
      description: 'cou_teaching_job_execute管理页面',
      sizeButton: 'default',
      dateFormat: 'YYYY-MM-DD',
      weekSetIndexDate: [],
      queryParam: {},
      classList: [],
      teachers: [],
      //查询条件联动部分定义

      teacherList: [],
      subjectList: [],
      queryParamSelect: {
        classIdSelect: 'cou_class,class_name,id,class_iz_open  =1 and class_iz_delete  = 0 order by  class_order'
      },
      // 表头
      columns: [],
      //列设置
      settingColumns: [],
      defColumns: [],
      //列定义 defColumns
      gudingColumns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key:'rowIndex',
        //   width:60,
        //   align:"center",
        //   customRender:function (t,r,index) {
        //     return parseInt(index)+1;
        //   }
        // },
        {
          title: '节次',
          align: 'center',
          dataIndex: 'teachingJobExeSection'

        },
        {
          title: '节次名',
          align: 'center',
          dataIndex: 'teaJobExeSectionName'
        }
      ],
      dongtaiColumns: [

        {
          title: '星期',
          align: 'center',
          dataIndex: 'teachingJobExeWeekName',//列名所在字段
          dataIndexId: 'teachingJobExeWeek',  //绑定数据字段
          nulldatacolname: '其他',
          valueIndex: 'teacherName',      //数据值取值字段
          subColumns: [
            //预留动态列多列分组展示，暂未实现，后期优化
            {
              title: 'id',
              align: 'center',
              width: 20,
              dataIndex: 'id'
            },
            {
              title: 'teacherName',
              align: 'center',
              width: 20,
              dataIndex: 'teacherName'
            },
            {
              title: 'className',
              align: 'center',
              width: 20,
              dataIndex: 'className'
            },
            {
              title: 'subjectName',
              align: 'center',
              width: 20,
              dataIndex: 'subjectName'
            },
            {
              title: 'classroomName',
              align: 'center',
              width: 20,
              dataIndex: 'classroomName'
            },
            {
              title: 'weekName',
              align: 'center',
              width: 20,
              dataIndex: 'weekName'
            },
            {
              title: 'holiday',
              align: 'center',
              width: 20,
              dataIndex: 'holiday'
            },
            {
              title: 'teachingJobExeDate',
              align: 'center',
              width: 20,
              dataIndex: 'teachingJobExeDate'
            },
            {
              title: 'weekSetIndex',
              align: 'center',
              width: 20,
              dataIndex: 'weekSetIndex'
            },
            {
              title: 'teachingJobExeWeek',
              align: 'center',
              width: 20,
              dataIndex: 'teachingJobExeWeek'
            },
            {
              title: 'classId',
              align: 'center',
              width: 20,
              dataIndex: 'classId'
            },
            {
              title: 'courseArrangeId',
              align: 'center',
              width: 20,
              dataIndex: 'courseArrangeId'
            },
            {
              title: 'quoteTeachingJobId',
              align: 'center',
              width: 20,
              dataIndex: 'quoteTeachingJobId'
            }
          ]
        }

      ],
      url: {
        list: '/couteachingjobexecute/couTeachingJobExecute/listAll',
        queryCourseArrange: '/coucoursearrange/couCourseArrange/list',
        queryByIdDetail: '/couteachingjobexecute/couTeachingJobExecute/queryByIdDetail',
        listDefaultWeekIndex: '/couteachingjobexecute/couTeachingJobExecute/list',
        changeCouresTeacher: '/couteachingjobexecute/couTeachingJobExecute/changeCouresTeacher',
        getTeacherAndSubjectCount: '/couteachingjobexecute/couTeachingJobExecute/getTeacherAndSubjectCount',
        changeCoures: '/couteachingjobexecute/couTeachingJobExecute/changeCoures',
        delete: '/couteachingjobexecute/couTeachingJobExecute/delete',
        deleteBatch: '/couteachingjobexecute/couTeachingJobExecute/deleteBatch',
        exportXlsUrl: '/couteachingjobexecute/couTeachingJobExecute/exportXls',
        importExcelUrl: 'couteachingjobexecute/couTeachingJobExecute/importExcel',
        queryClassUrl: '/classes/couClass/queryByGradeId'

      },
      dictOptions: {},
      superFieldList: [],
      whereData: [],
      weekSetIndex: 1,
      courArraAtomStartTime: [],
      viewTeacher: {},
      viewSubject: {},
      oneData: null,
      tooData: null,
      spinning: false,
      courseArrange: [],
      selectOnlTitle: '调换课程',
      jSelectOnlValue: '',
      changeObjs: {}
    }
  },
  //选择组件到内存中，这个时候 data 和methods是 加载好了的可以 在这里进行修改和调用，也是最早可以修改的时候
  created() {
    //this.initsubjectList()
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  watch: {
    weekSetIndexDate(newName, oldName) {
      console.log(newName)
      console.log(oldName)
    }
  },
  //dom从缓存挂载到浏览器完成后，如果需要修改demo中的节点或者值。这个时候是最早时候
  mounted() {
    this.getTeacherLists()
  },
  // 当子孙组件出错时，会调用这个钩子函数
  errorCaptured(err, vm, info) {
    console.log("这个是子孙组件返回的错误信息");
    console.log(err);
    console.log(vm);
    console.log(info);
  },
  methods: {
    handleCloseJselectOnl(val){
      this.loadData()
    },
    handTitleClick(obj) {
      console.log(obj)
    },
    //查询条件联动begin //////////////////////////////////////////////////////////////
    //初始化科目信息
    // async initsubjectList() {
    //   let subjectList = await getSubjectList()
    //   if (subjectList.code === 200) {
    //     this.subjectList = []
    //     subjectList.result.forEach(item => {
    //       this.subjectList.push({
    //         label: item.subjectName,
    //         value: item.subjectId
    //       })
    //     })
    //   }
    // },
    //科目变更-->更新教师列表
    async handleSubjectChange() {
      let tenantId = ''
      if (localStorage.length > 0) {
        let localData = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
        tenantId = localData.value.tenantId
        this.queryParam.tenantId = tenantId
      }
      let params = {
        tenantId: tenantId,
        subjectId: this.queryParam.subjectId
      }
      this.getTeacherLists(params)

    },
    //初始化教师
    async getTeacherLists(params) {
      var teaparams
      if (params) { //如果参数存在
        teaparams = params
      } else { //如果参数不存在
        let tenantId = ''
        if (localStorage.length > 0) {
          let localData = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
          tenantId = localData.value.tenantId
          this.queryParam.tenantId = tenantId
        }
        teaparams = {
          tenantId: tenantId,
          subjectId: null
        }
      }

      let res = await queryTeacherListBySubject(teaparams)
      if (res.success) {
        this.teacherList = []
        res.result.forEach(item => {
          this.teacherList.push({
            value: item.teacherId,
            label: item.teacherName
          })
        })
      }
    },
    //更改年级-->选择考试，选择班级
    changeGradeId() {
      if (this.queryParam.gradeId) { //判断不为空
        this.queryParamSelect.classIdSelect = 'cou_class,class_name,id,class_iz_open  =1 and class_iz_delete  = 0 and grade_code=\'' + this.queryParam.gradeId + '\' order by  class_order'
      }
    },

    //查询条件联动end //////////////////////////////////////////////////////////////
    customHeaderRow(columns, index) {
      return {
        on: {
          // 鼠标单击行
          dblclick: event => {
            console.log(columns)
            console.log(index)
          }
        }
      }
    },
    handleColTableQuery(obj) {
      if (obj.quoteTeachingJobId) {
        let params = {
          id: obj.quoteTeachingJobId,
          pageNo: 1,
          pageSize: 30
        }
        getAction(this.url.queryByIdDetail, params).then(res => {
          if (res.success) {
            this.changeObjs = res.result.pageList.records[0]
          } else {
            this.$message.error(res.message)
          }
        })
      } else
        this.changeObjs = {}
    },
    handleColTableChange(obj) {


      if (this.oneData === null) {
        this.oneData = obj
      } else if (this.tooData === null) {
        this.tooData = obj
      } else {
        this.$message.success('只能选择两节课做交换使用！如果需要多节课处理，请多次操作！')
        return
      }
      if (this.oneData != null && this.tooData != null) {
        if (this.oneData.id === this.tooData.id) {
          this.$message.success('同一节课不能进行交换！')
          this.tooData = null
          return
        }
      }

      /**
       * 点击后显示截止目前时间的教师课时和科目课时，暂时取消。后期看按需求放开
       */
      // var params = this.getQueryParams()
      // params['subjectId']= obj.subjectId;
      // params['teacherId']=obj.teacherId;
      // params['teachingJobExeDate']=obj.teachingJobExeDate;
      // postAction(this.url.getTeacherAndSubjectCount, params).then(res => {
      //   if (res.success) {
      //     this.viewTeacher = res.result.teacherCout[0];
      //     this.viewTeacher['teacherName'] = obj.teacherName;
      //     this.viewTeacher['teachingJobExeDate'] = obj.teachingJobExeDate;
      //     this.viewSubject = res.result.subjectCout[0];
      //     this.viewSubject['subjectName'] = obj.subjectName;
      //     this.viewSubject['teachingJobExeDate'] = obj.teachingJobExeDate;
      //
      //   } else {
      //     this.$message.error(res.message)
      //   }
      // })
      // 预留后期参照使用
      // if(this.arrySet.size < 2){
      //   this.arrySet.add(obj);
      //   if (this.oneData === null) {
      //     this.oneData = [...this.arrySet][0];
      //     let oneStyle = document.getElementById(this.oneData.id)//获取ID
      //     oneStyle.style = 'background-color: #7f7f7f'
      //   } else if (this.oneData.id === obj.id) {
      //     let oneStyle = document.getElementById(obj.id)//获取ID
      //     oneStyle.style = ''
      //     this.oneData = null
      //     this.arrySet.delete(obj);
      //   } else if (this.tooData === null) {
      //     this.tooData = [...this.arrySet][1];
      //     let tooStyle = document.getElementById(this.tooData.id)//获取ID
      //     tooStyle.style = 'background-color: #7f7f7f'
      //   } else if (this.tooData.id === obj.id) {
      //     let tooStyle = document.getElementById(obj.id)//获取ID
      //     tooStyle.style = ''
      //     this.tooData = null
      //     this.arrySet.delete(obj);
      //   }
      //
      // }else {
      //   this.$message.success('只能对两节课进行操作！')
      // }
    },
    onSelectBt(obj) {

      if (obj === 'one') {
        this.oneData = null
      } else if (obj === 'too') {
        this.tooData = null
      } else if (obj === 'oneWeek') {
        this.oneWeekData = null
      } else if (obj === 'tooWeek') {
        this.tooWeekData = null
      }

    },
    loadData() {
      this.listDefaultWeekIndex()
      if (!!this.queryParam.classId) {
        this.getTargetByClassId()
      }

    },
    onSetDate(obj) {
      console.log(obj)
      this.weekSetIndex = obj.weekSetIndex
      this.weekSetIndexDate = [
        obj.startDate,
        obj.endDate
      ]
      this.whereData.forEach(item => {
        item.types = ''
      })
      obj.types = 'primary'
      this.getTargetByClassId()
    },
    getClassByGradeId() {
      getAction(this.url.queryClassUrl, this.queryParam).then(res => {
        if (res.success) {
          this.classList = []
          res.result.forEach(item => {
            this.classList.push({
              label: item.className,
              value: item.id
            })
          })
        } else {
          this.$message.error(res.message)
        }
      })
    },
    getCourseArrangeId() {
      this.queryParam.targetObjId = this.queryParam.classId
      getAction(this.url.queryCourseArrange, this.queryParam).then(res => {
        if (res.success) {
          this.courseArrange = []
          res.result.records.forEach(item => {
            this.courseArrange.push({
              label: item.courseArrangeName,
              value: item.id
            })
          })
        } else {
          this.$message.error(res.message)
        }
      })
    },
    listDefaultWeekIndex() {
      var params = {}
      getAction(this.url.listDefaultWeekIndex, params).then(res => {
        if (res.success) {
          this.weekSetIndex = res.result.weekSetIndex
        } else {
          this.$message.error(res.message)
        }
      })
    },
    changeCouresTeacher() {
      console.log(this.teachers)
      if (!this.teachers || this.teachers.length < 1) {
        this.$message.success('请选择代课老师！')
        return
      }
      if (!this.oneData) {
        this.$message.success('请选择需要代课对象！')
        return
      }
      var params = {
        newTeacherId: this.teachers,
        oldCouTeachingJobExecute: this.oneData
      }
      this.spinning = true
      postAction(this.url.changeCouresTeacher, params).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.getTargetByClassId()
          this.spinning = false
          this.oneData = null
          this.tooData = null
          this.teachers = null
          this.oneWeekData = null
          this.tooWeekData = null
        } else {
          this.$message.error(res.message)
          this.spinning = false
        }
      })
    },
    getTargetByClassId() {

      this.queryParam.weekSetIndex = this.weekSetIndex
      var params = this.getQueryParams()
      var testdata = []
      getAction(this.url.list, params).then(res => {
        if (res.success) {

          testdata = res.result.pageList.records  // res.result.records
          // this.trRow2ColUtil3(testdata);
          this.trRow2ColInitColumns(testdata) //列名已经初始化了，只需初始化1次，不必重复初始化
          this.trRow2ColInitDatas(testdata)  //更新数据样式格式


          //this.dataSource = res.result.pageList.records
          if (res.result.pageList.total) {
            this.ipagination.total = res.result.pageList.total
          } else {
            this.ipagination.total = 0
          }
          this.courArraAtomStartTime = res.result.sectionAndTimeList
          this.whereData = res.result.whereInfo
          this.whereData.forEach(item => {
            item['types'] = ''
            if (item.weekSetIndex === this.weekSetIndex) {
              this.weekSetIndex = item.weekSetIndex
              this.weekSetIndexDate = [
                item.startDate,
                item.endDate
              ]
              item.types = 'primary'
            }

          })
        } else {
          this.$message.error(res.message)
        }
      })
    },
    exchangeCourse() {
      let params = {}
      if (this.oneData != null && this.tooData != null) {
        params = {
          oneData: this.oneData,
          tooData: this.tooData
        }
      } else if (this.oneWeekData != null && this.tooWeekData != null) {
        params = {
          oneWeekData: this.oneWeekData,
          tooWeekData: this.tooWeekData
        }
      } else {
        this.$message.success('请选择需要交换的对象！')
        return
      }
      this.spinning = true
      postAction(this.url.changeCoures, params).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.getTargetByClassId()
          this.spinning = false
          this.oneData = null
          this.tooData = null
          this.oneWeekData = null
          this.tooWeekData = null
        } else {
          this.$message.error(res.message)
          this.spinning = false
        }
      })
    },
    handleCleanSearch() {
      this.queryParam = {}
    },
    onChangeDate(value, dateString) {
      console.log(value)
      console.log(dateString)
    },
    initDictConfig() {

    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'courseArrangeId', text: '课表id' })
      fieldList.push({ type: 'date', value: 'teachingJobExeDate', text: '日期' })
      fieldList.push({ type: 'int', value: 'weekSetIndex', text: '周次表示第几周' })
      fieldList.push({ type: 'int', value: 'teachingJobExeWeek', text: '实际星期' })
      fieldList.push({ type: 'int', value: 'teachingJobExeNewWeek', text: '执行星期' })
      fieldList.push({ type: 'int', value: 'teachingJobExeSection', text: '节次' })
      fieldList.push({ type: 'number', value: 'teachingJobExeDuration', text: '课时量(上课持续时长)' })
      fieldList.push({ type: 'string', value: 'teacherId', text: '老师id' })
      fieldList.push({ type: 'string', value: 'subjectId', text: '科目id' })
      fieldList.push({ type: 'string', value: 'classroomId', text: '教室id' })
      fieldList.push({ type: 'string', value: 'classId', text: '班级id' })
      fieldList.push({
        type: 'string',
        value: 'teachingJobExeStatus',
        text: '上课状态（1正常，21代出课 22代入课(insert)，31交换出 32交换入）'
      })
      fieldList.push({ type: 'string', value: 'quoteTeachingJobId', text: '代换课引用教学任务数据id' })
      fieldList.push({ type: 'int', value: 'izOpen', text: '是否启用(1是启用，0否停用)' })
      fieldList.push({ type: 'string', value: 'tenantId', text: '学校id' })
      fieldList.push({ type: 'int', value: 'delFlag', text: '0表示未删除,1表示删除' })
      this.superFieldList = fieldList
    },
    trRow2ColInitColumns(testdata) {
      this.defColumns = [] //置空设置，防止重复设置
      this.columns = [] //置空设置，防止重复设置

      //第一次遍历，制做 表头
      var th = Object.assign([], th, this.gudingColumns)
      var thKeyCol = {} //动态关键列,需重新定义，动态获取

      //筛选动态列分项
      var thKey = {}
      for (var i = 0; i < testdata.length; i++) {
        var d = testdata[i]
        var dontaicolName = this.dongtaiColumns[0].dataIndex
        var dontaicolId = this.dongtaiColumns[0].dataIndexId
        if (d[dontaicolName] != undefined && d[dontaicolName] != null && d[dontaicolName] != 'null' && d[dontaicolName] != '') {
          // thKey[d[dontaicolName] ] =1 ;
          thKey[d[dontaicolName]] = d[dontaicolId]  //动态列

          // thKey[eval("d."+dontaicolId)] =2;
        } else if (d[dontaicolName] == null || d[dontaicolName] != 'null' || d[dontaicolName] != '') {
          thKey[this.dongtaiColumns[0].nulldatacolname] = this.dongtaiColumns[0].nulldatacolname  //动态列

        } else {
          thKey['-1'] = '-1'
        }

      }

      //把动态列加到th里面 ，动态增长列
      // for (var key in Object.keys(thKey))
      for (var key in thKey) {
        var colobj = {
          title: key, align: 'center', dataIndex: thKey[key],
          slots: { title: 'handTitle' },
          scopedSlots: {
            customRender: 'colName'
          }
        }
        th.push(colobj)
        thKeyCol[key] = key
      }
      this.defColumns = th
      this.columns = th
    },
    trRow2ColInitDatas(testdata) {
      //第二次遍历，制做tr的行
      var tr = [] //数据 [{}]

      for (var i = 0; i < testdata.length; i++) {
        var d = testdata[i]
        var rowdata = {}
        for (var j = 0; j < this.gudingColumns.length; j++) {
          rowdata[this.gudingColumns[j].dataIndex] = d[this.gudingColumns[j].dataIndex] //用对应列的数据赋值给固定列
        }


        //判断对象是否存在，存在则忽略，不存在则插入
        if (tr.length == 0) {
          tr.push(rowdata)
        } else {
          var insertflag = true
          for (var k in tr) {
            var eqflag = true
            for (var rd in rowdata) {
              if (rowdata[rd] !== tr[k][rd]) {
                eqflag = false
                continue
              }
            }
            //判断是否相等
            if (eqflag) {
              insertflag = false
            } else {
              continue
            }
          }
          //应当插入则插入：即不存在则插入
          if (insertflag) {
            tr.push(rowdata)
          }
        }

      }

      //第三次遍历，添加动态列的数据值:动态插入数据列
      for (var i = 0; i < testdata.length; i++) {
        var d = testdata[i]
        //查找应该是tr的第几条数据
        var trindex = -1
        for (var ti = 0; ti < tr.length; ti++) {
          var tr_rowdata = tr[ti]//取出1条数据
          var equalflag = true
          for (var j = 0; j < this.gudingColumns.length; j++) {
            if (tr_rowdata[this.gudingColumns[j].dataIndex] != d[this.gudingColumns[j].dataIndex]) { //用对应列的数据赋值给固定列
              equalflag = false
            }
          }
          //如果相等即找到了,则写入数据,考虑动态列寻找
          if (equalflag) {
            //直接赋值：给对应动态列的值设置为成绩数值（会存在空值串列的情况，需考虑空值设置问题）
            //考虑到数据是通过列名绑定，就不会存在串列问题
            if (d[this.dongtaiColumns[0].dataIndexId] != undefined && d[this.dongtaiColumns[0].dataIndexId] != null && d[this.dongtaiColumns[0].dataIndexId] != '') {
              // tr_rowdata[d[this.dongtaiColumns[0].dataIndexId]] = d[this.dongtaiColumns[0].valueIndex] //把指定的动态数据绑定到动态列名上
              var k_cell = {}
              for (var k = 0; k < this.dongtaiColumns[0].subColumns.length; k++) {
                var kcoltitle = this.dongtaiColumns[0].subColumns[k].title
                var kcolname = this.dongtaiColumns[0].subColumns[k].dataIndex
                k_cell[kcoltitle] = d[kcolname]
              }
              tr_rowdata[d[this.dongtaiColumns[0].dataIndexId]] = k_cell

            } else {
              // tr_rowdata[this.dongtaiColumns[0].nulldatacolname] = d[this.dongtaiColumns[0].valueIndex] //把成绩数据绑定到动态列名上
              var k_cell = {}
              for (var k = 0; k < this.dongtaiColumns[0].subColumns.length; k++) {
                var kcoltitle = this.dongtaiColumns[0].subColumns[k].title
                var kcolname = this.dongtaiColumns[0].subColumns[k].dataIndex
                k_cell[kcoltitle] = d[kcolname]
              }
              tr_rowdata[d[this.dongtaiColumns[0].dataIndexId]] = k_cell
            }
          }
          tr[ti] = tr_rowdata //重新定义一行数据，把动态列数据加入进来
        }

      }

      this.dataSource = tr  //重新定义数据：用分组动态列进行行列转换后的新数据

    },
    async trRow2Col() {
      //获得测试数据
      // var testdata = this.dataSource ;
      var testdata = []
      this.defColumns = []
      this.columns = []
      this.settingColumns = []

      var params = this.getQueryParams()//查询条件
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          testdata = res.result.records
          // this.trRow2ColUtil3(testdata);
          this.trRow2ColInitColumns(testdata) //列名已经初始化了，只需初始化1次，不必重复初始化
          this.trRow2ColInitDatas(testdata)  //更新数据样式格式

        }
      })


    }

  }
}
</script>
<style scoped>
.week-t {
  background-color: #e2e2e2;
  height: 40px;
  border: 1.5px solid #ffffff;
  color: #151515;
  line-height: 40px;
  font-weight: bold;
}

.liClass {
  font-weight: bold;
  width: 35px;
  line-height: 13px
}

.liClass-txt {
  font-weight: bold;
  width: 100px;
  line-height: 13px
}

.week-c {
  border: 1.5px solid #adadad;
  border-radius: 8%;
  width: 200px;
  text-align: center;
  margin: auto;
}

.week-b {
  margin: auto;
}

.week-c:hover {
  box-shadow: 0px 0px 6px #7f7f7f;
  background-color: #dcdcdc;
}

@import '~@assets/less/common.less';
</style>